package ml.ml.Dao;

import java.util.List;

import org.easycassandra.persistence.EasyCassandraManager;
import org.easycassandra.persistence.Persistence;

import ml.ml.Clases.Comentario;


public class ComentarioDAO {
	
	private Persistence persistence;
	private static Comentario comentario = new Comentario();
	private static ComentarioDAO instance;
	
	private ComentarioDAO() {
		this.persistence = EasyCassandraManager.getPersistence("mlp", "localhost", 9160);
	}
	
	public void create(Comentario bean) {
		this.persistence.insert(bean);
	}

	public void remove(Comentario bean) {
		this.persistence.delete(bean);
	}

    public void remove(final int id) {
        this.persistence.deleteByKeyValue(id, Comentario.class);
    }

	public void update(Comentario bean) {
		this.persistence.update(bean);
	}

	public Comentario retrieve(Object id) {
		return (Comentario) this.persistence.findByKey(id, comentario.getClass());
	}

	@SuppressWarnings("unchecked")
	public List<Comentario> listAll() {
		return this.persistence.findAll(comentario.getClass());
	}

	@SuppressWarnings("unchecked")
    public List<Comentario> listByIndex(Object index) {
		return this.persistence.findByIndex(index, Comentario.class);
	}
	
	public static ComentarioDAO getInstance() {
		if(instance == null) {
			instance = new ComentarioDAO();
		}
		return instance;
	}

}
